<script lang="ts">
import ManyButtons from '@/components/ManyButtons/index.vue'
import useMainStore from '@/store/main'
import { storeToRefs } from 'pinia'
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'CompWrapper',
  components: {
    ManyButtons,
  },
  props: {
    runSpeed: {
      type: Number,
      default: 0,
    },
  },
  emits: ['manyBtnClick'],
  setup() {
    const store = useMainStore()
    const { manyBtnShrink, runSpeedSim, isReal } = storeToRefs(store)
    return { manyBtnShrink, runSpeedSim, isReal }
  },
})
</script>

<template>
  <section class="home-page">
    <div class="main-content common-content">
      <div class="the-real-main">
        <slot />
      </div>
      <div class="fake-foot" :class="{ manyBtnShrink }"></div>
    </div>
    <div class="echarts-list common-content">
      <div class="the-real-main">
        <div class="floating-text">
          转速：{{ isReal ? runSpeed : runSpeedSim }} r/min
        </div>
        <slot name="echarts" />
      </div>
      <div class="fake-foot"></div>
    </div>
    <many-buttons class="button-content" :class="{ manyBtnShrink }" />
  </section>
</template>

<style scoped lang="scss">
.home-page {
  position: relative;
  height: 100%;
  display: flex;
  gap: var(--common-edge);
}

.fake-foot {
  height: var(--many-btn-height);
  flex-shrink: 0;
  transition: all 0.25s ease-in-out;

  &.manyBtnShrink {
    height: 0;
    margin-top: 0 !important;
  }
}

.the-real-main {
  position: relative;
  height: 100%;
  background: var(--panel-color);
  transition: all 0.25s ease-in-out;
  overflow: hidden;

  .floating-text {
    position: absolute;
    right: 6px;
    top: 6px;
    font-size: 18px;
    color: #fff;
    font-weight: normal;
  }
}

.common-content {
  display: flex;
  flex-direction: column;
  gap: var(--common-edge);
}

.main-content {
  height: 100%;
  width: 100%;
  gap: 0;

  .fake-foot {
    margin-top: var(--common-edge);
  }
}

.echarts-list {
  height: 100%;
  flex-shrink: 0;
  width: var(--echarts-width);
  overflow: hidden;
}

.button-content {
  position: absolute;
  bottom: 0;
  right: calc(-1 * var(--common-edge));
  width: calc(100% + var(--common-edge));
  transition: all 0.25s ease-in-out;

  &.manyBtnShrink {
    width: calc(var(--common-edge) + var(--echarts-width));
  }
}
</style>
